

// 从头或尾取K张卡牌, 使取得点数最大
int maxScore(int* cardPoints, int cardPointsSize, int k){
    int res = 0, sum = 0, l = cardPointsSize - k, r = cardPointsSize - 1;
    // 滑动窗口固定大小为k，通过k次滑动，遍历所有情况，可得出最大点数
    for (int i = l; i <= r; i++) sum += cardPoints[i];
    res = sum;
    while (k > 0) {
        sum -= cardPoints[l]; 
        l = (++l) % cardPointsSize;
        r = (++r) % cardPointsSize;
        sum += cardPoints[r];
        res = fmax(res, sum);
        k--;
    }  
    return res; 
}